# -*- coding:utf-8 -*-
# @Time: 2020/8/24 16:55
# @Author: liupengfei
# @File: format.py

import datetime
from datetime import timedelta


def strfdate(d):
    if d:
        return d.strftime('%Y-%m-%d')
    else:
        return ''


def strftime(t):
    if t:
        return t.strftime('%Y-%m-%d %H:%M')
    else:
        return ''


def strfsecond(second):
    sec = timedelta(seconds=second)
    d = datetime.datetime(1, 1, 1) + sec
    if d.hour > 0:
        if d.minute > 0:
            retval = "%d小时%d分钟" % (d.hour, d.minute)
        else:
            retval = "%d小时" % (d.hour)
    else:
        retval = "%d分钟" % (d.minute)
    return retval


def pageformat(page):
    num = len(page)
    page = "%02d-%s" % (num, page)
    return page
